package com.fan.gofast.util;


import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Random;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;

public class UUIDUtil {
	
	private static AtomicInteger atomicInteger=new AtomicInteger(0);

	public static String getUUID() {
		return UUID.randomUUID().toString().replaceAll("-", "");
	}

	/**
	 *  生成至少 17位以上的订单号
	 * 	
	 * @param size 长度
	 * @return
	 */
	public static String getSn(int size) {
		//SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddhhmmsssss");
		String newDate = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyyMMddHHmmssSSS"));
		StringBuffer result = new StringBuffer("");
		size = size - newDate.length();
		if (size <= 0) {
			return newDate;
		}
		for (int i = 0; i < size; i++) {
			result.append(atomicInteger.getAndAdd(1));
		}
		return newDate + result.toString();

	}

	public static String getSerialNumber(String prefix, int size) {
		return String.join("", prefix, getSn(size));
	}




	/**
	 *  生成N位数字随机字符串
	 * @param size 长度
	 * @return
	 */
	public static String getRandomNumber(int size) {
		StringBuffer result = new StringBuffer("");
		Random random = new Random();
		for (int i = 0; i < size; i++) {
			result.append(random.nextInt(10));
		}
		return  result.toString();
	}

	public static void main(String[] args) {
		System.out.println();
	}

}
